package mango.web.client.admin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import mango.web.client.C;
import mango.web.client.Vo;

public class MemberVo extends Vo {
	public Integer memberId;
	public String businessName = "";
	public String abn = "";
	public String businessType = "";
	public String other = "";
	public String membershipType = "";
	public String financialMember = "";
	public String annualReport = "";
	public Integer authorisedContact;
	public String marketingGroupUsed = "";
	public String packsOwnProduce = "";
	public String marketGroup = "";
	public String brand = "";
	public String status = "";

	public List<ContactVo> contactList = new ArrayList<ContactVo>();
	public List<OrchardVo> orchardList = new ArrayList<OrchardVo>();

	public List<FlowerVo> flowerList = new ArrayList<FlowerVo>();

	//////server search return values;
	public Integer current = null;
	public List<String> memberIdList = null;
	//public Boolean preAppended = null;
	public List<String> contactIdList = null;
	//public List<EmailVo> contactEmailList = null;
	public List<ContactVo> searchContactList = null;
	////////

	//public List<VarietyVo> varietyList;
	//public AdminDbVo adminDbVo;

	public String getStatus() {
		return C.getStatus(this.status);
	}

	public ContactVo getContact(String contactId) {
		ContactVo contact = null;
		for (int i = 0; i < this.contactList.size(); i++) {
			contact = this.contactList.get(i);
			if (contactId.equals(contact.contactId + "")) return contact;
		}
		return contact;
	}

	public OrchardVo getOrchard(String orchardId) {
		OrchardVo orchard = null;
		for (int i = 0; i < this.orchardList.size(); i++) {
			orchard = this.orchardList.get(i);
			if (orchardId.equals(orchard.orchardId + "")) return orchard;
		}
		return orchard;
	}

	public String getSampleMail(ContactVo selectedContact, String br) {
		StringBuffer sb = new StringBuffer();
		if (this.memberId.equals(selectedContact.mailMemberId)) {
			sb.append(this.businessName).append(br);
		}
		HashMap<String, String> contactNameMap = new HashMap<String, String>();
		for (int i = 0; i < this.contactList.size(); i++) {
			ContactVo contact = this.contactList.get(i);
			if (selectedContact.contactId.equals(contact.mailContactId)) {
				String str = contactNameMap.get(contact.surname);
				if (str == null) str = "";
				else str += " & ";
				str += contact.firstname;
				contactNameMap.put(contact.surname, str);
			}
		}
		boolean isFirst = true;
		for (String key : contactNameMap.keySet()) {
			if (isFirst) isFirst = false;
			else {
				sb.append(" and ");
			}
			sb.append(contactNameMap.get(key)).append(" ").append(key);
		}
		sb.append(br);
		sb.append(selectedContact.postalStreet).append(br);
		sb.append(selectedContact.postalCity).append(" ").append(selectedContact.postalState).append(" ").append(selectedContact.postalPostCode).append(br);
		return sb.toString();
	}
}
